package com.hanxiaozhang.order.controller;

import com.hanxiaozhang.exception.InternalServerException;
import com.hanxiaozhang.order.entity.User;
import com.hanxiaozhang.order.repository.UserRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * 功能描述: <br>
 * 〈UserController〉
 *
 * @Author:hanxinghua
 * @Date: 2020/6/28
 */
@Slf4j
@RestController
public class OldOrderController {

  @Autowired
  private UserRepository userRepository;

  @GetMapping("/{id}")
  public User findById(@PathVariable Long id) {
    User findOne = this.userRepository.findOne(id);
    if(id==1){
      throw new InternalServerException();
//      throw new NullPointerException();
    }
    return findOne;
  }


  @PostMapping(value = "/uploadFile")
  public String fileUpload(@RequestParam(value = "file") MultipartFile file) {
    log.info("uploadFile,fileName:{}",file.getOriginalFilename());
    return file.getOriginalFilename();
  }


}
